$setto(this,{$browser:{
    ie:     !!(window.attachEvent && !window.opera),
	ie50:   navigator.appVersion.indexOf("MSIE 5.0")>-1,
	ie55:   navigator.appVersion.indexOf("MSIE 5.5")>-1,
	ie60:   navigator.appVersion.indexOf("MSIE 6.0")>-1,
	ie70:   navigator.appVersion.indexOf("MSIE 7.0")>-1,
    opera:  !!window.opera,
    gecko:  navigator.userAgent.indexOf('Gecko') > -1,
    safari: navigator.appVersion.indexOf("Safari") > -1,
    webkit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    konqueror: navigator.appVersion.indexOf("Konqueror") > -1,
    mobsafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/),
    version: parseFloat(navigator.appVersion),
	setMoz: function(){
	    this.khtml = this.safari || this.konqueror;
        this.ff = this.moz = this.mozilla = this.gecko && (!this.khtml);
        if (this.moz){
	        var pos = navigator.userAgent.indexOf("Gecko");
	        this.mozillaVer = this.mozVer = this.ffVer = navigator.userAgent.substring(pos + 6, pos + 14);
        }	    
	}
}});
$browser.setMoz();

$setto(this,{$event:{
get: function(ev){
    return (ev ? ev : window.event);
},
cancel: function(ev){
    ev = this.get(ev);
    if(ev){
        ev.cancelBubble = true;
        if(ev.stopPropagation){ ev.stopPropagation(); }
        ev.returnValue = false;
        if(ev.preventDefault){ ev.preventDefault(); }
    }
    return false;
},
source: function(ev){
    ev = this.get(ev);
    var rtval = (ev.target ? ev.target : ev.srcElement);
    while(rtval && rtval.nodeType != 1){
      rtval = rtval.parentNode;
    }
    return rtval;
}
}});

$setto(Function.prototype,{
hook: function(element,eventName){
    if (element){
      if (!$browser.safari && element.addEventListener){
        element.addEventListener( eventName, this, false);
      } else if (!$browser.safari &&  element.attachEvent ){
        element.attachEvent('on' + eventName, this);
      } else{
        var handlers = element["x"+eventName];
        if (handlers && handlers.constructor == Array){
          if (handlers.contains(this)){
            handlers = null;
          } else {
            handlers.push(this);
          }
        } else {
          handlers = element["x"+eventName] = [this];
        }
        if (handlers){
          element['on' + eventName] = function(ev){
            var returnValue, undef = "undefined";
            ev = dom.Event(ev);
            for(var ndx=0; ndx < handlers.length; ++ndx){
              var handlerReturn = handlers[ndx](ev);
              if ( typeof handlerReturn != undef ){
                returnValue = handlerReturn;
              }
            }
            if (typeof returnValue != undef){
              return returnValue;
            }
          }
          element = null;
        }
      }
    }
    return this;
},
attach: function(element,eventName){
    return this.hook(element, eventName);
},
unhook: function(element,eventName){
    if (element){
      if (!$browser.safari && element.removeEventListener){
        element.removeEventListener( eventName, this, false );
      } else if (!$browser.safari && element.detachEvent){
        element.detachEvent( 'on' + eventName, this );
      } else{
        var arr = element["x"+eventName];
        if (arr && arr.constructor == Array){
          arr.remove( this );
        } else{
          element["on"+eventName] = null;
        }
      }
    }
    return this;
},
detach: function(element,eventName){
    return this.unhook(element, eventName);
},
exeonHtmled: function(args, ctx){
    var thsFun = this;
    var preFun = document.onreadystatechange;
    var tmpFun = function(){
        if (preFun) { $exes(preFun); }
        ctx = ctx || this;
        args = args || arguments;
        if (document.readyState == "interactive"){
            return thsFun.apply(ctx, $A(args));
        }
    };
    document.onreadystatechange = tmpFun;
},
exeonLoaded: function(args, ctx){
    var thsFun = this;
    var preFun = window.onload;
    var tmpFun = function(){
        if (preFun) { $exes(preFun); }
        ctx = ctx || this;
        args = args || arguments;
        return thsFun.apply(ctx, $A(args));
    };
    window.onload = tmpFun;
},
exeonClosed: function(args, ctx){
    $setto(window,{__WINDOW_CLOSED__:false});
    var thsFun = this;
    var preFuna = window.onunload;
    var preFunb = window.onbeforeunload;    
    var tmpFuna = function(){
        if (preFuna) { $exes(preFuna); }
        if (!!window.__WINDOW_CLOSED__){
            ctx = ctx || this;
            args = args || arguments;
            return thsFun.apply(ctx, $A(args));
        }
    };    
    var tmpFunb = function(){
        if (preFunb) { $exes(preFunb); }
        var n = window.event.screenX - window.screenLeft;
        var b = n > document.documentElement.scrollWidth - 20;
        window.__WINDOW_CLOSED__ = !!(b && window.event.clientY < 0 || window.event.altKey);
    };    
    window.onunload = tmpFuna;
    window.onbeforeunload = tmpFunb;
}});